﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataService;
using DTO;

public partial class Devices_Default : BasePage
{
    private const string DEVICE_TYPE_FILE = "D";
    private const string FIREWALL_TYPE_FILE = "F";

    private DeviceService _service;
    private IList<Device> _devices;
    public Devices_Default()
    {
        _service = new DeviceService();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (UserLogin == null)
        {
            Response.Redirect("~/Login.aspx");
        }
        if (!IsPostBack)
        {
            LoadGrid();
        }
    }

    private void LoadGrid()
    {
        _devices = _service.GetListDeviceByAccountId(UserLogin.Customer.Id);
        dlUsers.DataSource = _devices;
        dlUsers.DataBind();
    }
    protected void dlUsers_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Device device = (Device)e.Item.DataItem;
            Image imgDevice = (Image)e.Item.FindControl("imgDevice");
            switch (device.DeviceType)
            {
                case DEVICE_TYPE_FILE:
                    imgDevice.Width = 100;
                    imgDevice.Height = 100;
                    break;
                case FIREWALL_TYPE_FILE:
                    imgDevice.Width = 120;
                    imgDevice.Height = 43;
                    break;
                default:
                    break;
            }
        }
    }
}